class Script {
  process_incoming_request({ request }) {
    var c = request.content
    // console is a global helper to improve debug
    console.log(c)

    var commits = []
    for(var i=0; i<c.commits.length; i++) {
      var commit = c.commits[i]
      commits.push({
        title: commit.message,
        title_link: commit.url,
        author_name: commit.author.name,
        fields: [{
          title: "Timestamp",
          value: commit.timestamp
        }, {
          title: "Hash",
          value: commit.id
        }]
      })
    }

    var commit_text = "commit"
    if (c.length > 1) {
      commit_text += "s"
    }

    return {
      content: {
        alias: c.pusher.full_name,
        icon_url: c.pusher.avatar_url,
        text: c.commits.length + " " + commit_text + " pushed to [" + c.repository.full_name + "](" + c.repository.html_url + ") at " + c.ref,
        attachments: commits
      }
    }

    return {
       error: {
         success: false,
         message: 'Error'
       }
    }
  }
}
